package com.mpsc.seata.consumer.service.impl;


import com.mpsc.api.bean.UserInfoEntity;
import com.mpsc.seata.consumer.dao.UserInfoDao;
import com.mpsc.seata.consumer.service.UserInfoService;
import com.mpsc.seata.consumer.webService.WebUserInfoService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service("userInfoService")
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoDao userInfoDao;

    @Autowired
    private WebUserInfoService webUserInfoService;

    @Override
    @GlobalTransactional
    public void saveUserInfo(UserInfoEntity user) {
        System.out.println("-------执行saveUserInfo()方法之前-------");
        userInfoDao.saveUserInfo(user);
        user.setId(UUID.randomUUID().toString().hashCode());
        webUserInfoService.saveUserInfo(user);
        System.out.println("-------执行saveUserInfo()方法之后-------");
        throw new RuntimeException("测试seata回滚问题!!!");
    }
}
